package com.study.utils;

import java.sql.SQLException;

/**
 * 事务管理器，主要用于事务的开启，提交，回滚
 * @author Qi XueSong
 */
public class TransactionManager {

    private CollectionUtils collectionUtils;

    public void setCollectionUtils(CollectionUtils collectionUtils) {
        this.collectionUtils = collectionUtils;
    }

    // 开始事务的时候，禁用自动提交
    public void beginTransaction() throws SQLException {
        collectionUtils.getConnection().setAutoCommit(false);
    }

    // 提交事务
    public void commitTransaction() throws SQLException {
        collectionUtils.getConnection().commit();
    }

    // 回滚事务
    public void rollbackTransaction() throws SQLException {
        collectionUtils.getConnection().rollback();
    }
}

